﻿using System;

namespace ThresholdAssistant.Autofac
{
    /// <summary>
    /// Autofac工具类
    /// </summary>
    public static class AutofacProvider
    {
        /// <summary>
        /// Ioc容器
        /// </summary>
        public static IServiceProvider ServiceProvider { get; set; }

        /// <summary>
        /// 获取接口服务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T GetService<T>()
        {
            var serviceType = typeof(T);
            return (T)ServiceProvider.GetService(serviceType);
        }

        /// <summary>
        /// 获取接口服务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T GetService<T>(this Type serviceType)
        {
            return (T)ServiceProvider.GetService(serviceType);
        }
    }
}